package com.xtj.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.xtj.utils.RabbitMQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Porvider {
    //routing 订阅模型 topic
    public static void main(String[] args) throws IOException {
        Connection connection  = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();

        //将通道声明指定交换机 //参数1:交换机名称  //参数2:交换机类型 topic
        channel.exchangeDeclare("topics","topic");

        //发送消息
        String roukey = "user.save";
        channel.basicPublish("topics",roukey,null,("这是topic动态路由模型，roukey=["+roukey+"]").getBytes(StandardCharsets.UTF_8));

        //释放资源
        RabbitMQUtils.closeConnectionAndChanel(channel,connection);
    }
}
